var List = function() {
	this.keyArray = new Array();
	this.valArray = new Array();
};

List.prototype.add = function(key , val) {
	var idx = this.getIdx(key);
	
	if(idx == -1) {
		idx = 0;
		this.keyArray.push(key);
		this.valArray.push(val);
	}
	else {
		this.keyArray[idx] = key;
		this.valArray[idx] = val;
	}
	
	console.log("added("+idx+") - " + key + ":" + val);
};

List.prototype.remove = function(key) {
	var idx = this.getIdx(key);

	if(idx == -1) {
	}
	else {
		this.keyArray = this.keyArray.slice(0 , idx).concat( this.keyArray.slice(idx+1 , this.keyArray.length) );
		this.valArray = this.valArray.slice(0 , idx).concat( this.valArray.slice(idx+1 , this.valArray.length) );
	}
	
	console.log( this.keyArray );
	
};

List.prototype.getIdx = function(key) {
	var idx = -1;
	if(this.keyArray == null) return idx;
	if(!this.keyArray) return idx;
	for(var i = 0 ; i < this.keyArray.length ; i++) {
		if( this.keyArray[i] == key ) {
			idx = i;
			break;
		}
	}
	return idx;
};

List.prototype.clear = function() {
	this.keyArray = null;
	this.keyArray = new Array();
	this.valArray = null;
	this.valArray = new Array();
};




var StorageMapArrayList = function( storage_name ) {
	
	this.storage_name = storage_name;
	this.keyArray = this.getStorageKeyArray();
	this.valArray = this.getStorageValArray();
	this.setStorage();
};

StorageMapArrayList.prototype = List.prototype; // List를 상속

StorageMapArrayList.prototype.getStorageKeyArray = function() {
	var ret = window.localStorage.getItem( this.storage_name + '_keys' );
	if(ret == null) return new Array();
	else			return ret.split(',');
};

StorageMapArrayList.prototype.getStorageValArray = function() {
	var ret = window.localStorage.getItem( this.storage_name + '_values' ); if(ret == null) return new Array();
	return ret.split(',');
};

StorageMapArrayList.prototype.setStorage = function() {
	if( this.keyArray && this.keyArray != null && this.keyArray.length > 0 ) 	window.localStorage.setItem( this.storage_name + '_keys'   , this.keyArray );
	else																		window.localStorage.removeItem( this.storage_name+'_keys' );
	if( this.valArray && this.valArray != null && this.valArray.length > 0 )	window.localStorage.setItem( this.storage_name + '_values'   , this.valArray );
	else																		window.localStorage.removeItem( this.storage_name+'values' );
};

StorageMapArrayList.prototype.clear = function() {
	this.keyArray = null;
	this.keyArray = new Array();
	this.valArray = null;
	this.valArray = new Array();
	window.localStorage.removeItem( this.storage_name + '_keys' );
	window.localStorage.removeItem( this.storage_name + '_values' );
};